package com.ruoyi.jjyh.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.jjyh.domain.JjyhCar;
import com.ruoyi.jjyh.service.IJjyhCarService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 购物车Controller
 * 
 * @author ruoyi
 * @date 2020-11-26
 */
@Controller
@RequestMapping("/jjyh/car")
public class JjyhCarController extends BaseController
{
    private String prefix = "jjyh/car";

    @Autowired
    private IJjyhCarService jjyhCarService;

    @RequiresPermissions("jjyh:car:view")
    @GetMapping()
    public String car()
    {
        return prefix + "/car";
    }

    /**
     * 查询购物车列表
     */
    @RequiresPermissions("jjyh:car:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(JjyhCar jjyhCar)
    {
        startPage();
        List<JjyhCar> list = jjyhCarService.selectJjyhCarList(jjyhCar);
        return getDataTable(list);
    }

    /**
     * 导出购物车列表
     */
    @RequiresPermissions("jjyh:car:export")
    @Log(title = "购物车", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JjyhCar jjyhCar)
    {
        List<JjyhCar> list = jjyhCarService.selectJjyhCarList(jjyhCar);
        ExcelUtil<JjyhCar> util = new ExcelUtil<JjyhCar>(JjyhCar.class);
        return util.exportExcel(list, "car");
    }

    /**
     * 新增购物车
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存购物车
     */
    @RequiresPermissions("jjyh:car:add")
    @Log(title = "购物车", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(JjyhCar jjyhCar)
    {
        return toAjax(jjyhCarService.insertJjyhCar(jjyhCar));
    }

    /**
     * 修改购物车
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        JjyhCar jjyhCar = jjyhCarService.selectJjyhCarById(id);
        mmap.put("jjyhCar", jjyhCar);
        return prefix + "/edit";
    }

    /**
     * 修改保存购物车
     */
    @RequiresPermissions("jjyh:car:edit")
    @Log(title = "购物车", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(JjyhCar jjyhCar)
    {
        return toAjax(jjyhCarService.updateJjyhCar(jjyhCar));
    }

    /**
     * 删除购物车
     */
    @RequiresPermissions("jjyh:car:remove")
    @Log(title = "购物车", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(jjyhCarService.deleteJjyhCarByIds(ids));
    }
}
